package com.example.myowntodo.fet_probe.presentation

import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.myowntodo.R
import com.example.myowntodo.databinding.ActivityFetDialogCustomBinding
import com.example.myowntodo.testui.NotifyThenActivity

class FetDialogCustomActivity : AppCompatActivity() {
    // TODO: 这个操作是为了减少findViewById函数的调用的
    lateinit var binding: ActivityFetDialogCustomBinding


    var notification: Notification = NotificationCompat.Builder(this, "hello")
        .setContentTitle("官方通知")
        .setContentText("what the fuck")
        .setSmallIcon(R.drawable.ic_food)
        .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.about_logo))
//                .setContentIntent(pendingIntent)
//                .setAutoCancel(true)
        .build();

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()

        binding = ActivityFetDialogCustomBinding.inflate(layoutInflater)
        setContentView(binding.root)


//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
//            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
//            insets
//        }

//        notificationManager = getSystemService (NOTIFICATION_SERVICE) as NotificationManager;
//
//
//        val thenAct =  Intent(this, NotifyThenActivity::class.java);
//        val pendingIntent = PendingIntent.getActivity(this, 0, thenAct, PendingIntent.FLAG_MUTABLE);

        var notificationManager: NotificationManager =
            getSystemService(NOTIFICATION_SERVICE) as NotificationManager


        val b1 = findViewById(R.id.bt1) as Button


        notification =  NotificationCompat.Builder(this, "hello")
                .setContentTitle("官方通知")
                .setContentText("what the fuck")
                .setSmallIcon(R.drawable.ic_food)
//                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.about_logo))
//                .setContentIntent(pendingIntent)
//                .setAutoCancel(true)
                .build();

        b1.setOnClickListener {
            notificationManager.notify(1, notification)
        }
    }


}